package coreutil

import (
	"net/http"
	"strings"
)

type fileUtil struct {
}

func (p *fileUtil) GetFileContentType(data *[]byte) string {
	var buffer []byte
	if len(*data) < 512 {
		//		return "application/octet-stream"
		buffer = *data
	} else {
		buffer = (*data)[0:512]
	}

	contentType := http.DetectContentType(buffer)
	if "" == contentType {
		contentType = "application/octet-stream"
	}
	if strings.Index(contentType, ";") > 0 {
		var arr = strings.Split(contentType, ";")
		for _, v := range arr {
			if "charset=utf-8" != v {
				return v
			}
		}
	}
	return contentType
}

var (
	FileUtil = &fileUtil{}
)
